package com.clickpaas.governmentcloud.monitor;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.apache.commons.io.monitor.FileAlterationObserver;

import java.io.File;

@Slf4j
public class MonitorDic extends FileAlterationListenerAdaptor{
    private FileAnalysis fileAnalysis;

    // 采用构造函数注入服务
    public MonitorDic(FileAnalysis fileAnalysis) {
        this.fileAnalysis = fileAnalysis;
    }
    /**
     * 文件创建
     * @param file
     */
    @Override
    public void onFileCreate(File file){
        log.info("Create file：{}"+file);
        fileAnalysis.fileToPolicyEntity(file);
        log.info("file 导出成功");
    }

    /**
     * 文件删除
     */
    @Override
    public void onFileDelete(File file) {
        log.info("[删除]:({})" + file.getAbsolutePath());
    }

    /**
     * 文件修改
     */
    @Override
    public void onFileChange(File file){
        log.info("[修改]:({})" + file.getAbsolutePath());
    }

    /**
     * 目录创建
     */
    @Override
    public void onDirectoryCreate(File directory) {
        log.info("[新建]:({})" + directory.getAbsolutePath());
    }

    /**
     * 目录修改
     */
    @Override
    public void onDirectoryChange(File directory) {
        log.info("[修改]:({})" + directory.getAbsolutePath());
    }

    /**
     * 目录删除
     */
    @Override
    public void onDirectoryDelete(File directory) {
        log.info("[删除]:({})" + directory.getAbsolutePath());
    }

    @Override
    public void onStart(FileAlterationObserver observer) {
        // TODO Auto-generated method stub
        super.onStart(observer);
    }

    @Override
    public void onStop(FileAlterationObserver observer) {
        // TODO Auto-generated method stub
        super.onStop(observer);
    }
}
